<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>MagicSerializer.MagicSerializer</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  <script type="text/javascript" src="epydoc.js"></script>
</head>

<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="MagicSerializer-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

      <th class="navbar" width="100%"></th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <span class="breadcrumbs">
        <a href="MagicSerializer-module.html">Module&nbsp;MagicSerializer</a> ::
        Class&nbsp;MagicSerializer
      </span>
    </td>
    <td>
      <table cellpadding="0" cellspacing="0">
        <!-- hide/show private -->
        <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
    onclick="toggle_private();">hide&nbsp;private</a>]</span></td></tr>
        <tr><td align="right"><span class="options"
            >[<a href="frames.html" target="_top">frames</a
            >]&nbsp;|&nbsp;<a href="MagicSerializer.MagicSerializer-class.html"
            target="_top">no&nbsp;frames</a>]</span></td></tr>
      </table>
    </td>
  </tr>
</table>
<!-- ==================== CLASS DESCRIPTION ==================== -->
<h1 class="epydoc">Class MagicSerializer</h1><p class="nomargin-top"><span class="codelink"><a href="MagicSerializer-pysrc.html#MagicSerializer">source&nbsp;code</a></span></p>
<pre class="literalblock">

This class provide methods for serialize and deserialize and object. The file must have been serialized with this
class because only understands their format.

For serialize you need a structure data. The structure must be made by classes. Only this way is valid.

Public methods are: Serialize and Deserialize. And you can use it writing: 
    - MagicSerializer.Serialize(...)
    - MagicSerializer.Deserialize(...)

Examples:
=========

    1. Serialize a structure data into a xml file.
    
        The data:
        ---------------------------------------
        class one:
            def __init__(self):
                self.myvar = &quot;bye&quot;
                self.other = &quot;hello!&quot;
        class two:
            def __init__(self):
                self.name = &quot;cr0hn&quot;
                self.myclass = one()
        ---------------------------------------
        
        We want to save data serialized into XML file calle &quot;myproj.xml&quot;
        &gt;&gt; v = two()
        &gt;&gt; MagicSerializer.Serialize(v, &quot;myproj.xml&quot;)
        
        Now we can see results: 
        &lt;two&gt;                                                                                                                                                                                   
         &lt;one&gt;                                                                                                                                                                                  
           &lt;myvar&gt;bye&lt;/myvar&gt;                                                                                                                                                                   
           &lt;other&gt;hello!&lt;/other&gt;                                                                                                                                                                
         &lt;/one&gt;                                                                                                                                                                                 
         &lt;name&gt;cr0hn&lt;/name&gt;                                                                                                                                                                    
        &lt;/two&gt;
        
    2. Deserialize file info contain into. Deserializer need where is location of your data definition. We want to load serialized the next:
        - An XML file (named &quot;data.xml&quot;)
        - Into an object (named &quot;a&quot;)
        - Your library is located in &quot;mylibs.common.data&quot;
        - And our class is the same that above.
        
        &gt;&gt;a = MagicSerializer.Deserialize(two, &quot;data.xml&quot;, &quot;mylibs.common.data&quot;)
        &gt;&gt; print a.name
        cr0hn
        &gt;&gt; print a.myclass.myvar
        bye
    

</pre>

<!-- ==================== STATIC METHODS ==================== -->
<a name="section-StaticMethods"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Static Methods</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-StaticMethods"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="MagicSerializer.MagicSerializer-class.html#Serialize" class="summary-sig-name">Serialize</a>(<span class="summary-sig-arg">obj_</span>,
        <span class="summary-sig-arg">file_</span>)</span><br />
      Serialize an object into a file.</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="MagicSerializer-pysrc.html#MagicSerializer.Serialize">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr class="private">
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="MagicSerializer.MagicSerializer-class.html#_serialize" class="summary-sig-name" onclick="show_private();">_serialize</a>(<span class="summary-sig-arg">obj_</span>,
        <span class="summary-sig-arg">file_</span>,
        <span class="summary-sig-arg">level_</span>=<span class="summary-sig-default">0</span>)</span><br />
      Serialize an object</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="MagicSerializer-pysrc.html#MagicSerializer._serialize">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">object</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="MagicSerializer.MagicSerializer-class.html#Deserialize" class="summary-sig-name">Deserialize</a>(<span class="summary-sig-arg">obj_</span>,
        <span class="summary-sig-arg">file_</span>,
        <span class="summary-sig-arg">libs_</span>)</span><br />
      Deserialize an object</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="MagicSerializer-pysrc.html#MagicSerializer.Deserialize">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr class="private">
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">object</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="MagicSerializer.MagicSerializer-class.html#_deserialize" class="summary-sig-name" onclick="show_private();">_deserialize</a>(<span class="summary-sig-arg">obj_</span>,
        <span class="summary-sig-arg">dom_</span>)</span><br />
      Private function of deserializer.</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="MagicSerializer-pysrc.html#MagicSerializer._deserialize">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr class="private">
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="MagicSerializer.MagicSerializer-class.html#_deserializeParams" class="summary-sig-name" onclick="show_private();">_deserializeParams</a>(<span class="summary-sig-arg">root</span>,
        <span class="summary-sig-arg">object_result_</span>)</span><br />
      This method explore properties of a class/object</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="MagicSerializer-pysrc.html#MagicSerializer._deserializeParams">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr class="private">
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">bool</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="MagicSerializer.MagicSerializer-class.html#_isList" class="summary-sig-name" onclick="show_private();">_isList</a>(<span class="summary-sig-arg">obj_</span>)</span><br />
      Check if parameter is a list or dict type</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="MagicSerializer-pysrc.html#MagicSerializer._isList">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr class="private">
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">bool</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="MagicSerializer.MagicSerializer-class.html#_isSimple" class="summary-sig-name" onclick="show_private();">_isSimple</a>(<span class="summary-sig-arg">obj_</span>)</span><br />
      Check if parameter is a simple type like a int, str, long...</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="MagicSerializer-pysrc.html#MagicSerializer._isSimple">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
</table>
<!-- ==================== CLASS VARIABLES ==================== -->
<a name="section-ClassVariables"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Class Variables</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-ClassVariables"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
<tr class="private">
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a name="_libraries"></a><span class="summary-name">_libraries</span> = <code title="None">None</code>
    </td>
  </tr>
</table>
<!-- ==================== METHOD DETAILS ==================== -->
<a name="section-MethodDetails"></a>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Method Details</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-MethodDetails"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
</table>
<a name="Serialize"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">Serialize</span>(<span class="sig-arg">obj_</span>,
        <span class="sig-arg">file_</span>)</span>
    <br /><em class="fname">Static Method</em>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="MagicSerializer-pysrc.html#MagicSerializer.Serialize">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  <p>Serialize an object into a file.</p>
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>obj_</code></strong> (object) - object to serialize</li>
        <li><strong class="pname"><code>file_</code></strong> (str) - File path to write info</li>
    </ul></dd>
    <dt>Returns:</dt>
        <dd>no return.</dd>
  </dl>
</td></tr></table>
</div>
<a name="_serialize"></a>
<div class="private">
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">_serialize</span>(<span class="sig-arg">obj_</span>,
        <span class="sig-arg">file_</span>,
        <span class="sig-arg">level_</span>=<span class="sig-default">0</span>)</span>
    <br /><em class="fname">Static Method</em>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="MagicSerializer-pysrc.html#MagicSerializer._serialize">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  <p>Serialize an object</p>
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>obj_</code></strong> (object) - object to serialize</li>
        <li><strong class="pname"><code>file_</code></strong> (file handle) - File handle to write info</li>
        <li><strong class="pname"><code>level_</code></strong> (int) - deep level. Used for internal. Not be asigned.</li>
    </ul></dd>
    <dt>Returns:</dt>
        <dd>no return.</dd>
  </dl>
</td></tr></table>
</div>
<a name="Deserialize"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">Deserialize</span>(<span class="sig-arg">obj_</span>,
        <span class="sig-arg">file_</span>,
        <span class="sig-arg">libs_</span>)</span>
    <br /><em class="fname">Static Method</em>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="MagicSerializer-pysrc.html#MagicSerializer.Deserialize">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  <p>Deserialize an object</p>
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>obj_</code></strong> (object) - object type to deserialize</li>
        <li><strong class="pname"><code>file_</code></strong> (str) - path of file that contain xml info</li>
        <li><strong class="pname"><code>libs_</code></strong> (str) - String with location of libraries of data that want to be loaded:
          for example: &quot;thirdparty.mylibs&quot;</li>
    </ul></dd>
    <dt>Returns: object</dt>
        <dd>return an object filled as param obj_ type.</dd>
  </dl>
</td></tr></table>
</div>
<a name="_deserialize"></a>
<div class="private">
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">_deserialize</span>(<span class="sig-arg">obj_</span>,
        <span class="sig-arg">dom_</span>)</span>
    <br /><em class="fname">Static Method</em>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="MagicSerializer-pysrc.html#MagicSerializer._deserialize">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  <p>Private function of deserializer.</p>
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>obj_</code></strong> (object) - object type to deserializer.</li>
        <li><strong class="pname"><code>dom_</code></strong> (xml.dom.minidom.Document) - dom document from xml.dom.minidom.</li>
    </ul></dd>
    <dt>Returns: object</dt>
        <dd>object filled with xml info.</dd>
  </dl>
</td></tr></table>
</div>
<a name="_deserializeParams"></a>
<div class="private">
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">_deserializeParams</span>(<span class="sig-arg">root</span>,
        <span class="sig-arg">object_result_</span>)</span>
    <br /><em class="fname">Static Method</em>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="MagicSerializer-pysrc.html#MagicSerializer._deserializeParams">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  <p>This method explore properties of a class/object</p>
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>root</code></strong> (xml.dom.minidom.Document) - XML Node that contains properties associated to object 
          &quot;object_result_&quot;</li>
        <li><strong class="pname"><code>object_result_</code></strong> (Object) - Object to explore</li>
    </ul></dd>
    <dt>Returns:</dt>
        <dd>None</dd>
  </dl>
</td></tr></table>
</div>
<a name="_isList"></a>
<div class="private">
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">_isList</span>(<span class="sig-arg">obj_</span>)</span>
    <br /><em class="fname">Static Method</em>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="MagicSerializer-pysrc.html#MagicSerializer._isList">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  <p>Check if parameter is a list or dict type</p>
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>obj_</code></strong> (object) - object to check</li>
    </ul></dd>
    <dt>Returns: bool</dt>
        <dd>True if is a list, False otherwise</dd>
  </dl>
</td></tr></table>
</div>
<a name="_isSimple"></a>
<div class="private">
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">_isSimple</span>(<span class="sig-arg">obj_</span>)</span>
    <br /><em class="fname">Static Method</em>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="MagicSerializer-pysrc.html#MagicSerializer._isSimple">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  <p>Check if parameter is a simple type like a int, str, long...</p>
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>obj_</code></strong> (object) - object to check</li>
    </ul></dd>
    <dt>Returns: bool</dt>
        <dd>True if is a simple type, False otherwise</dd>
  </dl>
</td></tr></table>
</div>
<br />
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="MagicSerializer-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

      <th class="navbar" width="100%"></th>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
  <tr>
    <td align="left" class="footer">
    Generated by Epydoc 3.0.1 on Thu Jan 26 21:41:33 2012
    </td>
    <td align="right" class="footer">
      <a target="mainFrame" href="http://epydoc.sourceforge.net"
        >http://epydoc.sourceforge.net</a>
    </td>
  </tr>
</table>

<script type="text/javascript">
  <!--
  // Private objects are initially displayed (because if
  // javascript is turned off then we want them to be
  // visible); but by default, we want to hide them.  So hide
  // them unless we have a cookie that says to show them.
  checkCookie();
  // -->
</script>
</body>
</html>
